package com.common;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

import com.alibaba.fastjson.serializer.DoubleSerializer;
import com.alibaba.fastjson.serializer.SerializeConfig;

/**
 * Date: 12-7-10 Time: 上午9:33
 * 
 * 
 * @author pzb
 * @version 0.1
 */
public class Booter {
	public static void main(String[] args) throws Exception {
		Server server = make(args);
		server.start();
		server.join();
	}

	public static Server make(String[] args) throws Exception {
		Integer port = 8080;
		String webappDir = "webapp";
		String contextPath = "/";

		for (String arg : args) {
			if (arg.startsWith("-httpPort="))
				port = Integer.valueOf(arg.substring(10));
			if (arg.startsWith("-webappDir="))
				webappDir = arg.substring(11);
			if (arg.startsWith("-contextPath="))
				contextPath = arg.substring(13);
		}

		Server server = new Server(port);
		WebAppContext context = new WebAppContext();
		context.setContextPath(contextPath);
		context.setWar(webappDir);
		context.setExtractWAR(false);
		server.setHandler(context);

		return server;
	}
}
